package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;

public class JDBCQuick1 {
    public static void main(String[] args) throws Exception {
        Scanner sca = new Scanner(System.in);

        System.out.println("请输入员工姓名");
        String name = sca.nextLine();
        System.out.println("请输入员工年龄");
        int age = sca.nextInt();
        System.out.println("请输入员工薪水");
        double salary = sca.nextDouble();
        //1.获取链接
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/atguigu?characterEncoding=utf8&useSSL=false","root","8867993");

        System.out.println(connection);
        //2.编写sql，statement
        String sql = "insert into t_emp (emp_name,emp_age,emp_salary) values (?,?,?)";
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setString(1,name);
        statement.setInt(2,age);
        statement.setDouble(3,salary);

        //3.执行语句
        int i = statement.executeUpdate();
        statement.close();
        connection.close();
        sca.close();
    }
}
